package com.gongpingjialoan.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;


public class BuyCarCheckBox extends ImageView
{
    
    boolean checked = false;
    
    OnCheckChangeListener onCheckChangeListener;
    
    public boolean isChecked()
    {
        return checked;
    }
    
    public void setChecked(boolean checked)
    {
        this.checked = checked;
    }

    public OnCheckChangeListener getOnCheckChangeListener()
    {
        return onCheckChangeListener;
    }
    
    public void setOnCheckChangeListener(OnCheckChangeListener onCheckChangeListener)
    {
        this.onCheckChangeListener = onCheckChangeListener;
    }
    
    public BuyCarCheckBox(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        this.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                if (onCheckChangeListener != null)
                {
                    if (!isChecked())
                    {
                        onCheckChangeListener.onChange(BuyCarCheckBox.this, true);
                        checked = true;
                    }
                    else
                    {
                        onCheckChangeListener.onChange(BuyCarCheckBox.this, false);
                        checked = false;
                    }
                }
            }
        });
    }
    
    public BuyCarCheckBox(Context context)
    {
        super(context);
        this.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                if (onCheckChangeListener != null)
                {
                    if (!isChecked())
                    {
                        onCheckChangeListener.onChange(BuyCarCheckBox.this, true);
                    }
                    else
                    {
                        onCheckChangeListener.onChange(BuyCarCheckBox.this, false);
                    }
                }
            }
        });
    }
    
    public void addOnCheckChangeListener()
    {
        
    }
    
    public interface OnCheckChangeListener
    {
        void onChange(View v, boolean checked);
    }
}
